<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>开关按钮</title>
    <style>
        body {
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #e8e8e8;
        }

        .checkbox {
            display: none;
        }

        .slider {
            width: 60px;
            height: 30px;
            background-color: lightgray;
            border-radius: 20px;
            overflow: hidden;
            display: flex;
            align-items: center;
            border: 4px solid transparent;
            transition: .3s;
            box-shadow: 0 0 10px rgb(0, 0, 0, 0.25) inset;
            cursor: pointer;
        }

        .slider::before {
            content: '';
            display: block;
            width: 100%;
            height: 100%;
            background-color: #fff;
            transform: translateX(-30px);
            border-radius: 20px;
            transition: .3s;
            box-shadow: 0 0 10px 3px rgb(0, 0, 0, 0.25);
        }

        .checkbox:checked ~ .slider::before {
            transform: translateX(30px);
            box-shadow: 0 0 10px 3px rgb(0, 0, 0, 0.25);
        }

        .checkbox:checked ~ .slider {
            background-color: #2196f3;
        }

        .checkbox:active ~ .slider {
            transform: translate(0);
        }
    </style>
</head>
<body>
<label class="switch">
    <input type="checkbox" class="checkbox">
    <div class="slider"></div>
</label>

</body>
</html>